package main

import "fmt"

func counter(out chan <- int) { // 只可写入 int 类型的单向通道
	for i := 0; i < 10; i++ {
		out <- i
	}
	close(out)
}

func squarer(out chan <- int, in <- chan int) {
	for i := range in { // 只可向外读int类型的单向通道
		out <- i * i
	}
	close(out)
}

func printer(in <- chan int) {
	for i := range in {
		fmt.Println(i)
	}
}

func main() {
	ch1 := make(chan int)
	ch2 := make(chan int)
	go counter(ch1)
	go squarer(ch2, ch1)
	printer(ch2)



}
// 双向通道可以转变为单向，但是反过来则不行
